package com.anlu.thread.t8;

import java.util.concurrent.atomic.*;

public class Sequeue {
    private AtomicInteger value = new AtomicInteger(0);

    private int[] s = {2,1,4,6};

     AtomicIntegerArray a = new AtomicIntegerArray(s);

    AtomicReference<User> user = new AtomicReference<>();


    AtomicIntegerFieldUpdater<User> old = AtomicIntegerFieldUpdater.newUpdater(User.class,"old");

    public int next(){
        User user = new User();
        System.out.println(old.getAndIncrement(user));
        System.out.println(old.getAndIncrement(user));
        System.out.println(old.getAndIncrement(user));


        a.getAndIncrement(2);
        a.getAndAdd(2, 10);
        System.out.print("a=="+a.toString());
        return value.getAndIncrement();
    }

    public static void main(String[] args){
        Sequeue s = new Sequeue();

        new Thread(new Runnable() {

            @Override
            public void run() {
				while(true) {
                System.out.println(Thread.currentThread().getName() + " " + s.next());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
			}
            }
        }).start();
    }
}
